<template>
  <Blank>
    <div class="wrapper">
      <div class="con" v-if="worksList.length > 0">
        <div class="box" v-for="(item,index) in worksList" :key="index">
          <div class="poto">
            <div class="demo-image__preview">
              <el-image
                style="width: 100px; height: 100px"
                :src="item.url"
                :preview-src-list="srcList"
                :initial-index="index"
                hide-on-click-modal
                fit="cover"
              />
            </div>
          </div>
          <div class="des">
            {{ item.name }}
          </div>
        </div>
      </div>
      <div v-else class="not-con">暂无内容</div>
    </div>
  </Blank>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import Blank from "@/components/blankCard/BlankCard.vue";
import { useRoute } from "vue-router";
import { getWorksList } from "@/api/index";

const route = useRoute();
const worksList = ref([]);
const srcList = ref([]);

const initData = async () => {
  const res = await getWorksList(route.params.id);
  if (res) {
    worksList.value = res;
    res.forEach((item) => {
      srcList.value.push(item.url);
    });
  }
};
onMounted(() => {
  initData();
});
</script>

<style lang="scss" scoped>
.demo-image__error .image-slot {
  font-size: 30px;
}
.demo-image__error .image-slot .el-icon {
  font-size: 30px;
}
.demo-image__error .el-image {
  width: 100%;
  height: 200px;
}
.wrapper {
  margin-top: 140px;
  .con {
    margin: 50px 0 20px;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-left: -2%;
    .box {
      margin-left: 2%;
      margin-bottom: 30px;
      .poto {
        cursor: pointer;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
          transition: all 0.4s;
        }
      }
      .des {
        padding: 10px;
        font-size: 15px;
        color: #888;
        line-height: 25px;
        cursor: pointer;
      }
    }
  }
  .not-con {
    text-align: center;
    color: #888;
    font-size: 20px;
  }
}
</style>